//
//  ViewController.swift
//  LocationDemo
//
//  Created by 刘莹 on 2017/5/18.
//  Copyright © 2017年 liuying. All rights reserved.
//

import UIKit
import CoreLocation

class ViewController: UIViewController,CLLocationManagerDelegate {

    //定位管理器
   let locationManager :CLLocationManager = CLLocationManager()
  
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        locationManager.delegate = self //定位代理
        locationManager.desiredAccuracy = kCLLocationAccuracyBest //定位进度
        locationManager.distanceFilter = 10 //更新距离
        //locationManager.allowsBackgroundLocationUpdates = true
        locationManager.pausesLocationUpdatesAutomatically = false
        locationManager.requestAlwaysAuthorization() //发送授权
        if (CLLocationManager.locationServicesEnabled()) {
            locationManager.startUpdatingLocation()
            print("定位开始")
        }
        
       

        
    }
//定位改变执行
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        
        let currentLocation:CLLocation = locations.last!
        
        print("经度: \(currentLocation.coordinate.longitude)")
        print("纬度: \(currentLocation.coordinate.latitude)")
        
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

